﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.ETL.Infrastructure
{
    public class TypeUtil
    {
        /// <summary>
        /// 将数据库类型转换为csharp的数据类型
        /// </summary>
        /// <param name="dbType"></param>
        /// <returns></returns>
        public static Type ConvertFromDbType(string dbType)
        {
            if(string.Equals(dbType, "bigint"))
            {
                return typeof(long);
            }
            else if (string.Equals(dbType, "int"))
            {
                return typeof(int);
            }
            else if(string.Equals(dbType, "uniqueidentifier"))
            {
                return typeof(Guid);
            }
            else if(string.Equals(dbType, "datetime"))
            {
                return typeof(DateTime);
            }
            else if(string.Equals(dbType, "bit"))
            {
                return typeof(bool);
            }
            else
            {
                return typeof(string);
            }
        }

        /// <summary>
        /// 将数据库类型转换为csharp的数据类型
        /// </summary>
        /// <param name="csType"></param>
        /// <returns></returns>
        public static Type ConvertFromCSType(string csType)
        {
            if (string.Equals(csType, typeof(long).FullName))
            {
                return typeof(long);
            }
            else if (string.Equals(csType, typeof(int).FullName))
            {
                return typeof(int);
            }
            else if (string.Equals(csType, typeof(Guid).FullName))
            {
                return typeof(Guid);
            }
            else if (string.Equals(csType, typeof(DateTime).FullName))
            {
                return typeof(DateTime);
            }
            else if (string.Equals(csType, typeof(bool).FullName))
            {
                return typeof(bool);
            }
            else
            {
                return typeof(string);
            }
        }
    }
}
